package memorystresser;

public class MemoStress {
	private class Daten {
		private long[] data;
		public Daten daten;

		public Daten() {
			data = new long[10000];
			for (int i = 0; i < data.length; i++) {
				data[i] = i;
			}
		}
	}

	public static void main(String[] args) {
		int counter = 0;
		while ( true ){
			try {
				counter++;
				System.out.println("Try: " + counter + " ...");
				new MemoStress().test();
			} catch ( OutOfMemoryError error ){
				System.out.println(error);
			}
			System.out.println();
		}
	}

	public void test() {
		long start = System.currentTimeMillis();

		Daten d = new Daten();
		Daten root = d;
		for (int i = 0; i < 100000; i++) {
			d.daten = new Daten();
			d = d.daten;
		}

		long end = System.currentTimeMillis();
		System.out.println("Time: " + (end - start));
	}
}
